package com.skyolder.milkbee.service;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.skyolder.milkbee.domain.Card;
import com.skyolder.milkbee.domain.Comment;
import com.skyolder.milkbee.dto.HisPost;
import com.skyolder.milkbee.repository.CardRepository;
import com.skyolder.milkbee.repository.CommentRepository;
import com.skyolder.milkbee.service.mapper.HisPostMapper;

@Service
@Transactional
public class HisPostService {
	//private final Logger log = LoggerFactory.getLogger(HisPostService.class);

	@Inject
	private CardRepository cardRepository;
	@Inject
	private CommentRepository commentRepository;

	@Inject
	private HisPostMapper hisPostMapper;

	public Page<HisPost> findCardsByUserId(Long userId, Pageable pageable) {
		Page<Card> result = cardRepository.findByUserId(userId, pageable);
		return result.map(card -> {
			HisPost hp = hisPostMapper.cardToHisPost(card);
			hp.setType(HisPost.CARD_TYPE);
			return hp;
		});
	}

	public Page<HisPost> findCommentsByUserId(Long userId, Pageable pageable) {
		Page<HisPost> result = commentRepository.doQueryByUserId(userId, pageable);
		return result;
	}

}
